package com.dangdang.action.cart;

import com.dangdang.action.BaseAction;
import com.dangdang.service.CartService;
import com.dangdang.service.ServiceFactory;
import com.dangdang.util.Constants;

/**
 * 添加商品到 购物车小票控制层 <br>
 * 
 * 用户在商品列表页面点击购买按钮以后，<br>
 * 就将其选购的商品条目(CartItem) 添加到了购物车中<br>
 * 
 * @author Wangpeihu
 * @team [Never give up]
 * @since JDK1.6(建议)
 * @date 2010-1-29
 */
public class AddCartItemAction extends BaseAction {

	private boolean showcart = false;

	public boolean isShowcart() {
		return showcart;
	}

	public void setShowcart(boolean showcart) {
		this.showcart = showcart;
	}

	/** 购物车综合控制类 */
	private CartService cartService;

	/** 商品类 */
	private Integer productId;

	/** 被选购商品的状态： */
	private Integer status;

	public Integer getProductId() {
		return productId;
	}

	public void setProductId(Integer productId) {
		this.productId = productId;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public String execute() {

		cartService = ServiceFactory.getCartService(session);
		boolean b = cartService.addItem(productId);
		// 添加商品到购物车时会检测用户是否登录
		if (showcart) {
			return "success";
		} else {
			status = b ? Constants.CART_STATUS_OK : Constants.CART_STATUS_EXIST;
			return "json-success";
		}
	}

}
